package com.google.googlemarket.adapter;

import android.text.format.Formatter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

import com.google.googlemarket.MyApp;
import com.google.googlemarket.R;
import com.google.googlemarket.bean.HomeBean;
import com.google.googlemarket.http.BitmapHelp;
import com.google.googlemarket.http.Urls;

import java.util.ArrayList;

/**
 * Created by Administrator on 2017/9/19.
 */
public class HomeAdapter extends MyBaseAdapter<HomeBean.AppInfo>{
    private ArrayList<String> mDatas;

    public HomeAdapter(ArrayList<HomeBean.AppInfo> datas) {
       super(datas);
    }

    @Override
    protected int getItemLayoutId(int position) {
        return R.layout.item_app_list;
    }

    @Override
    protected Object createViewHolder(View convertView, int position) {
        ViewHolder holder = new ViewHolder();
        holder.iv_icon = (ImageView) convertView.findViewById(R.id.iv_icon);
        holder.tv_name = (TextView) convertView.findViewById(R.id.tv_name);
        holder.tv_size = (TextView) convertView.findViewById(R.id.tv_size);
        holder.tv_desc = (TextView) convertView.findViewById(R.id.tv_desc);
        holder.rating_bar = (RatingBar) convertView.findViewById(R.id.rating_bar);
        return holder;
    }

    @Override
    protected void showData(int position, Object holder, HomeBean.AppInfo data) {
        ViewHolder viewHolder = (ViewHolder) holder;
        String iconUrl = Urls.IMAGE + "?name=" + data.iconUrl;
        BitmapHelp.getBitmapUtils(MyApp.getmContext()).display(viewHolder.iv_icon,iconUrl);
        viewHolder.tv_name.setText(data.name);
        viewHolder.tv_size.setText(Formatter.formatFileSize(MyApp.getmContext(), data.size));
        viewHolder.tv_desc.setText(data.des);
        viewHolder.rating_bar.setRating(data.stars);

    }

    public class ViewHolder {
        ImageView iv_icon;
        TextView tv_name;
        TextView tv_size;
        TextView tv_desc;
        RatingBar rating_bar;
    }
}
